package project.Mapper;

import org.apache.ibatis.annotations.*;
import project.Pojo.Chat.AI.ChatRecord;
import project.Pojo.Chat.ChatRoom;
import project.Pojo.Chat.ChatRoomUser;

import java.sql.Date;
import java.util.List;

@Mapper
public interface ChatMapper {
    //    聊天室表
    @Insert("insert into  chat_room(name, admin) value (#{name}, #{admin})")
    void insertRoom(String name, String admin);

    @Select("select id from chat_room where name = #{name}")
    int selectRoomId(String name);

    @Delete("delete from chat_room where id = #{id}")
    void deleteRoom(int id);

    @Select("select * from chat_room where id = #{id}")
    List<ChatRoom> selectRoomById(int id);

    //按用户id查询AI聊天记录中所有用户发的信息
    @Select("select msg_id,msg_date,msg_content,msg_role from ai_chat_message where user_id = #{userId}")
    @Results({
            @Result(property = "msgId", column = "msg_id"),
            @Result(property = "msgDate", column = "msg_date"),
            @Result(property = "msgContent", column = "msg_content"),
            @Result(property = "msgRole", column = "msg_role")
    }
    )
    List<ChatRecord> getRecordByUserId(String userId);

    @Insert("insert into ai_chat_message(msg_content,msg_date,msg_role,user_id) " +
            "value (#{msgContent},#{msgDate},#{msgRole},#{userId})")
    void insertAiRecord(ChatRecord chatRecord);


    //    聊天室用户表
    @Select("select * from chat_room_users where room_id = #{roomId} and username = #{username}")
    ChatRoomUser selectRoomUserByRoomIdAndUsername(int roomId, String username);

    @Insert("insert into chat_room_users(username, room_id) value ( #{admin}, #{id})")
    void insertRoomUser(String admin, int id);

    @Delete("delete  from chat_room_users where room_id = #{RoomId} and username = #{username}")
    void deleteRoomUser(int RoomId, String username);
}
